﻿
@{
    ViewData["Title"] = "客户管理|恩腾五金ERP";
    Layout = "~/Views/Shared/_layout2.cshtml";
}


@using ETWJ.DTO
@model List<CompanyDTO>

    <form method="post" action="">
        <div class="panel admin-panel">
            <div class="panel-head"><strong class="icon-reorder"> 客户管理</strong></div>
            <div class="padding border-bottom">
                <ul class="search">
                    <li>
                        <button type="button" class="button border-green" id="checkall"><span class="icon-check"></span> 全选</button>
                        <button type="button" id="addEmployee" class="button border-blue"><span class="icon-road"></span> 添加</button>
                        <button type="button" id="editEmployee" class="button border-blue"><span class="icon-edit"></span> 修改</button>
                        <button type="button" id="deletedEmployee" class="button border-red"><span class="icon-trash-o"></span> 批量删除</button>

                    </li>
                </ul>
            </div>
            <table class="table table-hover text-center">
                <tr>
                    <th width="120">ID</th>
                    <th>公司姓名</th>
                    <th>公司电话</th>
                    <th>老板姓名</th>
                    <th>加入公司时间</th>
                </tr>

                @foreach (var company in Model)
                {
                    <tr>
                        <td>
                            <input type="checkbox" name="id[]" value="@company.Id" />
                            @company.Id
                        </td>
                        <td>@company.CompanyName</td>
                        <td>@company.PhoneNum</td>
                        <td>@company.BossName</td>
                        <td>@company.AddTime</td>
                    </tr>
                }


                <tr>
                    <td colspan="11">
                        <div class="pagelist">
                            <a href="/Company/List?PageIndex=1">首页</a>
                            <a href="/Company/List?PageIndex=@(Convert.ToInt32(@ViewBag.CurrentPageIndex-1)>0?Convert.ToInt32(@ViewBag.CurrentPageIndex-1):1)">上一页</a>
                            @for (var i = 1; i <= ViewBag.PageCount; i++)
                            {
                                @*<span class="current"></span>*@
                                if (i == ViewBag.CurrentPageIndex)
                                {
                                    <a href="/Company/List?PageIndex=@i" style="background-color:#09F; color:white;">@i</a>
                                }
                                else
                                {
                                    <a href="/Company/List?PageIndex=@i">@i</a>
                                }

                            }
                            <a href="/Company/List?PageIndex=@((Convert.ToInt32(ViewBag.CurrentPageIndex)+1)>ViewBag.PageCount?ViewBag.PageCount:(Convert.ToInt32(ViewBag.CurrentPageIndex)+1))">下一页</a>
                            <a href="/Company/List?PageIndex=@ViewBag.PageCount">尾页</a>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </form>
    <script type="text/javascript">

        function del(id) {
            if (confirm("您确定要删除吗?")) {

            }
        }

        $("#checkall").click(function () {
            $("input[name='id[]']").each(function () {
                if (this.checked) {
                    this.checked = false;
                }
                else {
                    this.checked = true;
                }
            });
        })

        function DelSelect() {
            var Checkbox = false;
            $("input[name='id[]']").each(function () {
                if (this.checked == true) {
                    Checkbox = true;
                }
            });
            if (Checkbox) {
                var t = confirm("您确认要删除选中的内容吗？");
                if (t == false) return false;
            }
            else {
                alert("请选择您要删除的内容!");
                return false;
            }
        }

    </script>


    <script>

        $(function () {

            // 点击新增用户按钮
            $("#addEmployee").click(function () {
                window.location.href = "/Company/Add";
            });

            // 修改用户
            $("#editEmployee").click(function () {
                var ids = new Array();　//创建一个数组  ;
                $("input[name='id[]']").each(function () {
                    if (this.checked) {
                        ids.push($(this).val());

                    }
                });
                if (ids.length <= 0) {
                    alert("请选中一个再进行修改操作！");
                    return;
                }
                if (ids.length >= 2) {
                    alert("只能选中一个进行修改操作！");
                    return;
                }

                //alert(ids)
                window.location.href = "/Company/Edit?id=" + ids;
            });

            // 删除/批量删除
            $("#deletedEmployee").click(function () {
                var ids = new Array();　//创建一个数组  ;
                $("input[name='id[]']").each(function () {
                    if (this.checked) {
                        ids.push($(this).val());

                    }
                });
                if (ids.length <= 0) {
                    alert("请选中一个再进行删除操作！");
                    return;
                }
                if (confirm("您确定要删除吗?")) {
                    //alert(ids)
                    window.location.href = "/Company/BatchDeleted?ids=" + ids;
                }

            });
        })
    </script>


